
<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
                <a-form-model-item label="年份">
                   <year-select :show-all="true" :value.sync="queryParam.startDate" :value2.sync="queryParam.endDate" />
                </a-form-model-item>
            </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->
    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
    </div>
    <!-- table区域-begin -->
    <div>
      <a-table 
      :columns="columns" 
      @expandedRowRender="expandedRowRender" 
      :data-source="dataSource"
      :rowKey="item => item.year"
       :pagination="ipagination"
      :loading="loading"
      class="j-table-force-nowrap"
      @change="handleTableChange"
      >
      
       <span slot="operation" slot-scope="text, record">
          <a @click="handleDetails(record)">查看</a>
          <a-divider type="vertical" />
          <a @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical" />
          <a @click="clickdelete(record.year)">删除</a>
        </span>
          <a-table
          slot="expandedRowRender"
           slot-scope="record" 
          :columns="innerColumns"
          :data-source="record.marketAverageList"
          :pagination="false"
          >
         </a-table>
      </a-table>
    </div>
    <market-AvPrice-modal ref="modalForm" @ok="modalFormOk" @close="close"></market-AvPrice-modal>
  </a-card>
</template>

<script>
  import { getAction } from '@/api/manage'
  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import marketAvPriceModal from './modal/marketAvPriceModal.vue'
  import JDictSelectTag from '@/components/dict/JDictSelectTag.vue'
  import YearSelect from '@/components/jeecg/YearDateSelect.vue'
  import { delMarketAvPrice } from '@/api/dashboardPaltform'
  import NP from 'number-precision'
  export default {
    name: 'marketAvPriceList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      YearSelect,
      JDictSelectTag,
      marketAvPriceModal,
    },
    data () {
      return {
        createTime:[],
        positionList:[],
        description: '枇杷市场均价',
        innerColumns : [
            { title: '品种', dataIndex: 'varietyIdName', key: 'varietyIdName' },
            { title: '单个品种均价（元/斤）', dataIndex: 'average', key: 'average' },
        ],
        // 表头
         columns: [
            { title: '年份', dataIndex: 'year', key: 'year' },
            { title: '各品种均价（元/斤）', dataIndex: 'average', key: 'average' },
            { title: '操作', key: 'operation', scopedSlots: { customRender: 'operation' } },
        ],  
        dataSource:[],
        innerData:[],
        isorter:{
        },
        url: {
          list: "/marketAverage/queryPage",
          delete: "/marketAverage/del",
        },
        dictOptions:{},
      }
    },
    mounted() {
        this.getTxppSubjectList()
    },
    computed: {
    },
    methods: {
       close(){
          this.searchQuery()
        },
        getNum(val){
          return NP.round(val, 2) + '%'
        },
        clickdelete(id) {
          this.$confirm({
            title: '您确定要删除该条记录吗？',
            onOk: () => {
              this.delMarketAvPrice(id)
            },
            onCancel() {
              console.log('Cancel')
            },
            centered: true,
          })
        },
        async delMarketAvPrice(val) {
            let res = await delMarketAvPrice({year:val})
            if(res.success){
              this.$message.success(res.message)
              this.searchQuery()
            }else{
              this.$message.error(res.message)
            }
        },
        getTxppSubjectList() {
            getAction('/loquat/txppSubject/allList').then((res) => {
                this.positionList = res.result
            })
        },
        onDateChange: function (value, dateString) {
            this.queryParam.startDate=dateString[0];
            this.queryParam.endDate=dateString[1];
        },
        initDictConfig(){
        }
    }
  }
</script>
<style scoped lang="less">
  @import '~@assets/less/common.less';
.table-page-search-wrapper{
/deep/ .ant-calendar-range-picker-input{
    font-size: 12px
  }
}
</style>